<?php

namespace app\api\controller;

use app\api\model\Category as CategoryModel;
use app\api\model\WxappCategory as WxappCategoryModel;

/**
 * 商品分类控制器
 * Class Goods
 * @package app\api\controller
 */
class Category extends Controller
{
    /**
     * 分类页面
     * @return array
     * @throws \think\exception\DbException
     */
    public function index()
    {

        //查看有没有这个店员
        $shop_check = db('store_shop_clerk')
            ->where('user_id', input()['user_id'])
            ->where('is_delete', 0)
            ->find();

        // 分类模板
        $templet = WxappCategoryModel::detail();
        $list = array_values(CategoryModel::getCacheTree());

        //d($shop_check);
        // 商品分类列表
        // 如果不是店员
        if (!$shop_check) {
            //print_r(6666);
//            if (isset(input()['manba'])) {
//                foreach ($list as $k => $v) {
//                    if ($v['category_id'] != 10012 && strpos($v['name'], '活动') == false) {
//                        unset($list[$k]);
//                    }
//                }
//            } else {
//                foreach ($list as $k => $v) {
//                    if ($v['category_id'] == 10012 || strpos($v['name'], '活动') !== false) {
//                        unset($list[$k]);
//                    }
//                }
//            }

            foreach ($list as $k => $v) {
                if ($v['type'] == 2) {
                    unset($list[$k]);
                }
            }

        } else {

//            if (isset(input()['manba'])) {
//                foreach ($list as $kk => $vv) {
//                    if ($vv['category_id'] != 10012) {
//                        unset($list[$kk]);
//                    }
////
//                }
//                $list[0] = $list[4];
//                unset($list[4]);
////
//            }

            if (isset(input()['manba'])) {
                foreach ($list as $k => $v) {
                    if ($v['type'] == 1) {
                        unset($list[$k]);
                    }
                }
            }


        }

        $list = array_values($list);
        return $this->renderSuccess(compact('templet', 'list'));

    }

}
